package frontend.model.worklog;

import backend.model.other.MonthState;
import frontend.model.base.UIModel;
import shared.other.MonthStateEnum;

public class MonthStateUIModel implements UIModel<MonthState> {

    private Integer month; //1-based
    private Integer year;

    private MonthState monthState;
    private MonthStateEnum currentStatus;
    private MonthStateEnum newStatus = MonthStateEnum.CLOSED;

    public MonthStateUIModel(int month, int year) {
        this.month = month;
        this.year = year;
        this.currentStatus = MonthStateEnum.OPENED;
        this.newStatus = MonthStateEnum.CLOSED;
        monthState = new MonthState();
    }

    public MonthStateUIModel(MonthState dbMonthState) {
        this.monthState = dbMonthState;
        this.newStatus = MonthStateEnum.CLOSED;
        populateFieldsFromDBModel();
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public MonthState getMonthState() {
        return monthState;
    }

    public void setMonthState(MonthState monthState) {
        this.monthState = monthState;
        populateFieldsFromDBModel();
    }

    public MonthStateEnum getCurrentStatus() {
        return currentStatus;
    }

    public void setCurrentStatus(MonthStateEnum currentStatus) {
        this.currentStatus = currentStatus;
    }

    @Override
    public MonthState getDBModel() {
        return monthState;
    }

    @Override
    public void populateDBModelFromFields() {
        monthState.setMonth(month);
        monthState.setYear(year);
        monthState.setState(newStatus);
    }

    @Override
    public void populateFieldsFromDBModel() {
        month = monthState.getMonth();
        year = monthState.getYear();
        currentStatus = monthState.getState();
    }

    public MonthStateEnum getNewStatus() {
        return newStatus;
    }

    public void setNewStatus(MonthStateEnum newStatus) {
        this.newStatus = newStatus;
    }

    public String getCurrentStatusDisplayValue() {
        return currentStatus.getDisplayValue();
    }
}
